package cn.edu.zafu.bigdata.x.xiejunjie;

public class Cube {
    private double length;
    private double width;
    private double height;

    // 构造方法
    public Cube(double length, double width, double height) {
        this.length = length;
        this.width = width;
        this.height = height;
    }

    // 获取方法
    public double getLength() {
        return length;
    }

    public double getWidth() {
        return width;
    }

    public double getHeight() {
        return height;
    }

    // 重写 equals 方法
    @Override
    public boolean equals(Object obj) {
        // 检查是否为同一个对象
        if (this == obj) {
            return true;
        }
        // 检查对象是否为 null 或类型是否不同
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        // 转换为 Cube 类型
        Cube other = (Cube) obj;
        // 比较属性值
        return Double.compare(this.length, other.length) == 0 &&
                Double.compare(this.width, other.width) == 0 &&
                Double.compare(this.height, other.height) == 0;
    }

    // 重写 hashCode 方法（可选，但建议实现）
    @Override
    public int hashCode() {
        int result = 17;
        long temp;
        temp = Double.doubleToLongBits(length);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(width);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(height);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        return result;
    }
}
